XF.APP = new function(){

	this.addAPP = function(){
		XF.lightSideBar("addAPP");
		var url  = global.contextPath + "/app/add"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#barCenter").html(xhr);
		  }
		});
	};
	
	this.listAPPSearch = function(orderByFieldReq){
		var orderByField = null;
		var orderByMode = null;
		var companyName = null;
		var appType = null;
		var appStatus = null;
		
		companyName = $("input[name=companyName]").val();
		appType = $("select[name=appType]").val();
		appStatus = $("select[name=appStatus]").val();
		
		if(typeof(orderByFieldReq)!='undefined' && orderByFieldReq!=""){
			orderByField = orderByFieldReq;
			var td = $("th[orderByField="+orderByField+"]");
			orderByMode = td.find("span.px").attr("orderByMode");
		}

		 _bar_search(orderByField,orderByMode,companyName,appType,appStatus);
	};
	
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		} 
	};
	
	this.deleteApp = function(id){
		$.messager.confirm('提示',"确认删除这条记录吗？",function(r){
		    if (r){
				var url  = global.contextPath + "/app/doDelete"
				$.ajax({
				  url: url,
				  type: "post",
				  data: {id:id},
				  complete: function(xhr){
					  xhr = xhr['responseText'];
					  xhr = new Function("return " + xhr);
					  xhr = xhr();
					  xhr = xhr['status'];
					  if(xhr=="SUCCESS"){
						  $.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						  });
						  $(".userListWrap tr i[s="+id+"]").parent().parent().parent().remove();
					  }else if(xhr=="FAILD"){
						  $.messager.show({
							title:'提示',
							msg:'删除失败',
							timeout:5000,
							showType:'slide'
						  });
					  }
				   }
				});
		    }
		});
	};
	
	this.modifyApp = function(id){
		var url  = global.contextPath + "/app/edit"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {id:id},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#barCenter").html(xhr);
		  }
		});
	};
	
	this.manageAPP = function(){
		XF.lightSideBar('manageAPP');
		_bar_search(null,null,null,null,null);
	};

    function _bar_search(orderByField,orderByMode,companyName,type,status){
        config.app_search['args'] = [orderByField,orderByMode,companyName,type,status];
        SMT.xconfig.gvar.pageNum = '1';
        SMT.ajax(config.app_search);
    }
	
}();

config.app_search = {
		url: ""+global.contextPath+"/app/manageList",
	    argsOrder: ['orderByField','orderByMode','companyName','appType','appStatus'],
	    needVar: true,
	    replaceExp: '#barCenter',
	    callBack: function() {
	    }		
};
